package com.zhuiyun.project.api.wxlogin.controller;


import com.zhuiyun.project.api.wxlogin.entiy.WxLoginVo;
import com.zhuiyun.project.api.wxlogin.service.WxLoginService;

import com.zhuiyun.project.api.appuser.model.AppUserModel;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Description TODO 小程序微信授权登录
 * @ClassName WxLoginController
 * @Author HH
 * @Date 2023/4/10 19:03
 **/
@RestController
@RequestMapping("/wxLogin")
public class WxLoginController extends BaseController {

    @Autowired
    WxLoginService wxLoginService;

    /**
     * @param code
     * @Description 获取openid
     * @Author HH
     * @Date 2023/4/11 11:04
     * @Return com.zhuiYun.project.common.response.CommonResult
     */
    @PostMapping("/getOpenid")
    public CommonResult getOpenid(@RequestBody String code) throws IOException {
        return wxLoginService.getOpenid(code);
    }


    /**
     * @param user
     * @Description 小程序微信授权用户登录
     * @Author HH
     * @Date 2023/4/10 18:55
     * @Return com.zhuiYun.project.common.response.CommonResult
     */
    @PostMapping("/login1")
    public CommonResult login(@RequestBody AppUserModel user) {
        return wxLoginService.login(user);
    }


    /**
     * @param phone
     * @Description 腾讯云发送手机短信
     * @Author HH
     * @Date 2023/4/12 9:43
     * @Return com.zhuiYun.project.common.response.CommonResult
     */
    @GetMapping("/sendPhoneCode")
    public CommonResult sendPhoneCode(String phone) {
        return wxLoginService.sendPhoneCode(phone);
    }

    /**
     * @Description 判断手机短信验证码是否正确
     * @Author HH
     * @Date 2023/4/12 13:55
     * @Return com.zhuiYun.project.common.response.CommonResult
     */
    @GetMapping("/verificationCode")
    public CommonResult verificationCode(String phone, String code) {
        return wxLoginService.verificationCode(phone, code);
    }

    /**
     * @Description 获取手机号
     * @Author HH
     * @Date 2023/4/12 13:55
     * @Return com.zhuiYun.project.common.response.CommonResult
     */
    @PostMapping("/getPhoneNum")
    public CommonResult getPhoneNum(@RequestBody WxLoginVo wxLoginVo) {
        return wxLoginService.getPhoneNum(wxLoginVo);
    }
}

